package com.zxl.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * 连接SQLServer数据库工具类
 * @author zxl
 *
 */
public class DBconnection {
	
	private static Connection dbConn = null;
	public Connection getConnection() throws SQLException{
		/*
		 * 通过读取dbproperties.properties文件获取数据库连接
		InputStream inputstream = this.getClass().getClassLoader().getResourceAsStream("dbproperties.properties");
		Properties p = new Properties();
		try {
			p.load(inputstream);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		String driverName = p.getProperty("SQLServer_DriverName"); //加载JDBC驱动
		String dbURL = p.getProperty("SQLServer_URL"); //连接服务器和数据库
		String userName = p.getProperty("SQLServer_USERNAME"); //默认用户名
		String userPwd = p.getProperty("SQLServer_PASSWORD"); //密码
		
		try {
			Class.forName(driverName);
			dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		
		//通过proxool连接池获取连接
		try {
			Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
			dbConn = DriverManager.getConnection("proxool.DBPool");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dbConn;
	}
	
	
	public static void main(String args[]){
//		InputStream inputstream = ClassLoader.getSystemResourceAsStream("dbproperties.properties");
//		Properties p = new Properties();
//		try {
//			p.load(inputstream);
//			System.out.println(p.getProperty("SQLServer_DriverName"));
//			System.out.println(p.getProperty("SQLServer_URL"));
//		} catch (IOException e1) {
//			e1.printStackTrace();
//		}
	}

}
